package com.firefly.mobile.app.config;

import java.util.HashMap;
import java.util.Map;

import com.firefly.app.biz.enums.ReturnCodeEnum;

/**
 * 交易信息配置
 * 
 * @author Brain
 * 
 */
public class Config {

	public static Map<String, String> CONF_MAP =  new HashMap<String, String>();

	
	/**
	 * 获得配置Integer值
	 * 
	 * @param key 配置关键字
	 * @return Integer值
	 */
	public static Integer getInteger(String key) {
		Integer v = null;
		if (CONF_MAP != null) {
			v = Integer.parseInt(CONF_MAP.get(key));
		}
		if (v == null) {
			throw new RuntimeException("参数配置错误,key=" + key);
		}
		return v;
	}
	
	/**
	 * 获得配置String值
	 * 
	 * @param key 配置关键字
	 * @return Integer值
	 */
	public static String getString(String key) {
		String v = null;
		if (CONF_MAP != null) {
			v = CONF_MAP.get(key);
		}
		if (v == null) {
			throw new RuntimeException("参数配置错误,key=" + key);
		}
		return v;
	}
	
	/** 前置 */
	public static class FRONT {

		//TODO 暂时固定一个数值
		public static final String TERM_NO = "99999999";
	}
	
	// ------------------配置相关常量------------------//
	/** System */
	public static class System {

		public static final String CONTEXT_PATH = Config.getString("system.contextPath");

		
	}
	
	
	//日志配置
	public static class LogInfo{
		public static final String LOG_FILE_PATH = CONF_MAP.get("log.filePath");
		public static final String LOG_MAX_LENGTH = CONF_MAP.get("log.maxLength");
		public static final String LOG_MAX_FILENUM = CONF_MAP.get("log.maxFileNum");
	}

	//交易流水号配置
	public static class TransNoProperties {
		public static final String NEXT_NO_KEY = "transNo.next_no";
	}
	
	
	/**
	 * 获得返回码JSON数据
	 * 
	 * @return 返回码JSON数据
	 */
	public static String getCodeJSon() {
		StringBuffer buf = new StringBuffer(); 
		buf.append("{");
		ReturnCodeEnum[] enumArray = ReturnCodeEnum.values();
		String flag = "";
		for (ReturnCodeEnum enumItem : enumArray) {
			buf.append(flag).append("\""+enumItem.name()+"\"").append(":\"").append(enumItem.getCode()).append("\"");
			flag = ",";
		}
		buf.append("}");
		return buf.toString();
	}

	
}
